package com.team.controller;

import com.team.dto.RegistrationDTO;
import com.team.service.RegistrationService;
import com.team.vo.Result;
import com.team.vo.VolunteerInfoVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping
@Slf4j
public class RegistrationController {
    @Autowired
    private RegistrationService registrationService;

    /**
     * 添加报名信息
     * @param registrationDTO
     * @return
     */
    //TODO只能3志愿？
    @PostMapping("/addRegistration_information")
    public Result addRegistrationInfo(@RequestBody RegistrationDTO registrationDTO){
        log.info("添加报名信息：{}",registrationDTO);
        registrationService.addRegistrationInfo(registrationDTO);
        return Result.success();
    }

    /**
     * 删除报名信息
     * @param cid
     * @param studentId
     * @return
     */
    @PostMapping("/deleteRegistration_information")
    public Result deleteRegistrationInfo(int cid,@RequestParam("student_id") int studentId){
        registrationService.deleteRegistrationInfo(cid,studentId);
        return Result.success();
    }

    /**
     * 获取所有团队的一志愿个数
     * @param studentId
     * @return
     */
    @GetMapping("/getVolunteer-modify")
    public Result<List<VolunteerInfoVo>> getVolunteer(@RequestParam("student_id") int studentId){
        List<VolunteerInfoVo> volunteerInfos=registrationService.getVolunteer(studentId);
        return Result.success(volunteerInfos);
    }

    /**
     * 更改志愿
     * @param studentId
     * @param status
     * @param cid
     * @return
     */
    @PostMapping("/updateVolunteer-modify")
    public Result volunteerModify(@RequestParam("student_id") int studentId,int cid,int status){
        registrationService.volunteerModify(studentId,status,cid);
        return Result.success();
    }
}
